#/bin/bash

defaultfile='preproxy2.ini'
runas='d639599'

file=0
usage()
{
	echo "usage: spdctrl start|stop|refresh|restart [ini_file]"
}

getfile(){
	if [ ! -z  $1 ];then
		if [ ! -f $1 ]; then
			echo "Could not find ini file $1"
			exit 1
		else
			file=$1
			echo $file
		fi	
	else
		if [ ! -f $defaultfile ]; then
			echo "Could not find default ini file $defaultfile"
			exit 1
		else
			file=$defaultfile
		fi

	fi

}


case $1 in 
	start)
		echo "starting server\n"
		#seteuid(
	;;
	stop)
		echo "stopping server\n"
		getfile $2
		cat `cat $file | sed -n 's/pidfile=\(.*\)/\1/pg'` | xargs kill -SIGTERM
		if [ $? != 0 ]; then
			echo "no pid"
		else
			echo "stopped"
		fi
	
	;;
	refresh)
		echo "refresh server\n"
		getfile $2
		cat `cat $file | sed -n 's/pidfile=\(.*\)/\1/pg'` | xargs kill -SIGHUP

	;;
	*)
		usage
	;;
esac

